Skip to content

fix(spec): unlock the archive lock before its file closes - #91

Draft
runewright[bot] wants to merge 1 commit into
mainfrom
change/archive-lock-release
Draft

runewright[bot] wants to merge 1 commit into
mainfrom
change/archive-lock-release

Conversation

@runewright

@runewright runewright Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Draft for change/archive-lock-release: the session agent fills this body before rune sign open.

Plan

Why this shape, one or two sentences.

Changes

  • Fill in: verb-first, file-anchored claims the diff upholds.

Testing

  • Fill in: the command run and its outcome.

Release Notes

  • N/A

Note

Unlock spec archive lock before its file closes

  • Adds a HeldLock guard in mod.rs that wraps the lock file and explicitly unlocks it on Drop, before the descriptor closes. This fixes retries that fail when a child process holds a copied descriptor, since a close alone does not release the lock in that case.
  • Transaction now stores a HeldLock instead of a File, and acquire_with_io, health_findings, and incomplete_transaction_findings all use the guard, including on early returns.
  • Adds a regression test in tests.rs that duplicates the lock descriptor, drops the transaction, and verifies another transaction can acquire the lock. The test is ignored on Windows.
  • Risk: if the explicit unlock fails, the file close still releases the lock as before, so behavior is unchanged on Windows.

Macroscope summarized 8521a5e.

The transaction held the archive lock as a plain File and released it only
by closing the file. The lock is a flock on the open file description, so
a child process that another thread spawned while the lock was held kept a
copy of the descriptor until it exec-ed or exited, and the lock with it.
An immediate retry then failed with "another spec archive transaction
holds" the lock: spec::tests::archive_retry_reports_the_existing_dated_archive
failed that way on the cli 84 Test job, because rune-docs unit tests run as
threads of one process and the doctor tests spawn children.

HeldLock unlocks in Drop before the close, for the transaction and for the
doctor probe. A new test holds a duplicate descriptor, drops the
transaction, and takes the lock again; it fails with the CI error without
the unlock. In a stress loop with four spawning threads, 26 of 2000
retries failed before the change and 0 of 2000 after.

Co-Authored-By: Martin Zeman <N4M3Z@users.noreply.github.com>
@github-actions github-actions Bot added size:small auto: changed-lines bucket area:docs auto: documentation and markdown labels Nov 24, 2026
@runeseer

runeseer Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

review/correctness round 1 started on 8521a5e0 at ledger generation 1.

@runeseer

runeseer Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @Runewright[bot]'s task in 3m 4s —— View job


Correctness review

  • Read the diff against origin/main
  • Read the lane inputs and ledger
  • Trace every lock-release path
  • Write the verdict

Looks good. HeldLock::drop calls unlock() before the descriptor closes, so a forked child's inherited copy of the fd no longer keeps the spec archive lock held after a transaction ends. On Unix the flock belongs to the open file description, and close releases it only once every fd referring to that description is closed, so the explicit LOCK_UN is the correct fix.

Verified:

  • Both construction sites carry HeldLock now (rune-docs/src/spec/transaction/mod.rs:269, :697), and the old _lock: File field has no remaining holder.
  • The wrap happens with no fallible step between try_lock() and HeldLock(lock) (mod.rs:247-259, :633-644), so no window drops a locked File unwrapped.
  • Every early return after the wrap unlocks on the way out: health_findings at mod.rs:648 and :652, and incomplete_transaction_findings at :681 and :688.
  • HeldLock is only ever built over a File whose try_lock() returned Ok, so the drop never unlocks an unlocked descriptor.
  • The new test is a real regression test: try_clone shares the open file description, so without the unlock() the second acquire would hit WouldBlock and panic (tests.rs:308-317).
  • The changelog entry satisfies rune-docs/src/changelog.rs: [Unreleased] is the first release heading, the entry is verb-first, under the 200-character limit, and carries no em-dash or type: prefix.

Minor, non-blocking:

  • The same close-only release pattern remains at other lock sites — the deploy target lock (src/cli/deploy/mod.rs:116) and the signer repository lock (src/cli/sign/queue/store.rs:325) both rely on File drop. Out of scope for this PR, but the same child-process window applies. Fix this →
  • The PR body is still the unfilled template — the Plan, Changes, and Testing sections need filling before rune sign open.

I could not run cargo test -p rune-docs transaction in this environment (the command is outside my allowed tools), so the review above is static. Add Bash(cargo test:*) to --allowedTools if you want the suite exercised here.
· change/archive-lock-release

@runeseer

runeseer Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Runeseer review — clean

Looks good. HeldLock::drop releases the flock before the descriptor closes, so a forked child's inherited copy no longer keeps the spec archive lock held after a transaction ends.

  • Every construction site now carries HeldLock, and each early return in health_findings and incomplete_transaction_findings unlocks on the way out.
  • Minor: other lock sites, such as the deploy target lock and the signer repository lock, still release by close alone.
  • The PR body is still the unfilled template.

No open findings · Reviewed 8521a5e0 · review run · $1.15 · 3m4s · 27 turns

@runeseer runeseer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earned approval: review/correctness returned a clean verdict for 8521a5e at ledger generation 1. Dismissed automatically on any new push or generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs auto: documentation and markdown size:small auto: changed-lines bucket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants